<%@ page contentType="text/html; charset=utf-8" pageEncoding="iso-8859-2" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<s:layout-render name="/jsp/layout.jsp" titlekey="admin.students.title">
    <s:layout-component name="header"></s:layout-component>

    <s:layout-component name="body">
        <%@include file="../menu.jsp"%>
        <s:useActionBean beanclass="cz.muni.fi.pa165.languageschool.web.StudentActionBean" var="actionBean"/>
        <sec:authentication property="authorities" var="role" scope="page"/>
        <c:choose>
            <c:when test="${role} == ROLE_ADMIN">
                <h2>
                    <f:message key="admin.students.title"/>
                </h2>
            </c:when>
            <c:otherwise>
                <h2>
                    <f:message key="student.entity.enrolledLectures"/><strong> ${actionBean.student.firstName} ${actionBean.student.lastName}</strong>
                </h2> 
            </c:otherwise>
        </c:choose>

        <fieldset>
            <legend>
                <f:message key="student.entity.enrolledLectures"/> <strong>${actionBean.student.firstName} ${actionBean.student.lastName} (${actionBean.student.id})</strong>
            </legend>
            <table>
                <tr>
                    <th><f:message key="lecture.entity.id"/></th>
                    <th><f:message key="lecture.entity.label"/></th>
                    <th><f:message key="lecture.entity.lecturer"/></th>
                    <th><f:message key="lecture.entity.tpDay"/></th>
                    <th><f:message key="lecture.entity.course"/></th>
                </tr>
                <c:forEach items="${actionBean.enrolledLectures}" var="lecture">
                    <tr>
                        <td class="content"><c:out value="${lecture.id}"/></td>
                        <td class="content"><c:out value="${lecture.label}"/></td>
                        <td class="content"><c:out value="${lecture.lecturer.lastName} ${lecture.lecturer.firstName}"/></td>
                        <td class="content"><c:out value="${lecture.tpDay} ${lecture.tpTime}"/></td>
                        <td class="content"><c:out value="${lecture.course.code} ${lecture.course.name}"/></td>
                        <td>
                            <sec:authorize access="hasRole('ROLE_ADMIN')"> 
                                <s:form beanclass="cz.muni.fi.pa165.languageschool.web.StudentActionBean">
                                    <s:hidden name="student.id" value="${student.id}"/>
                                    <s:hidden name="lecture.id" value="${lecture.id}"/>
                                    <s:submit id="button" name="disenroll">
                                        <f:message key="student.disenroll.label"/>
                                    </s:submit>
                                </s:form>
                            </sec:authorize>
                        </td>
                    </tr>
                </c:forEach>
            </table>

        </fieldset>


        <sec:authorize access="hasRole('ROLE_ADMIN')"> 
            <s:form beanclass="cz.muni.fi.pa165.languageschool.web.StudentActionBean">

                <fieldset>
                    <legend>
                        <f:message key="student.enroll.label"/>
                    </legend>
                    <s:errors/>
                    <s:hidden name="student.id" value="${student.id}"/>

                    <table>
                        <tr>
                            <td><s:select id="b3" name="lectureId">
                                    <s:options-collection collection="${actionBean.lectures}" value="id" label="label"/>
                                </s:select>
                            </td>
                            <td>
                                <s:submit id="button" name="enroll">
                                    <f:message key="student.enroll.label"/>
                                </s:submit>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <s:submit id="button" name="cancelEdit">
                    <f:message key="student.cancel.label"/>
                </s:submit>
            </s:form>
        </sec:authorize>         
    </s:layout-component>
</s:layout-render>